
import 'package:flutter/material.dart';
import 'package:spring_dict/UI/Component/MessageDialog.dart';
import 'package:spring_dict/UI/Pages/AboutPage.dart';
import 'package:spring_dict/UI/Pages/AppsPage/ActivePage.dart';
import 'package:spring_dict/UI/Pages/AppsPage/FavouritesPage.dart';
import 'package:spring_dict/UI/Pages/AppsPage/MeFollowTo.dart';
import 'package:spring_dict/UI/Pages/AppsPage/ToFollowMe.dart';
import 'package:spring_dict/UI/Pages/AppsPage/WordManagementPage.dart';

class AppsPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    final menus = <AppsMenuItem>[
      AppsMenuItem(
        label: "ئاكتىپ ھەركەتلەر",
        imageAsset: "assets/pictures/hot-air-balloon.png",
        animationTag: "Activation-Page-Logo",
          action: (context) => Navigator.of(context).push(MaterialPageRoute(builder: (context) => ActivePage()))
      ),
      AppsMenuItem(
        label: "يىغىپ ساقلىغۇچ",
        imageAsset: "assets/pictures/favourites.png",
        animationTag: "Favourite-Page-Tag",
    action: (context) => Navigator.of(context).push(MaterialPageRoute(builder: (context) => FavouritesPage()))
      ),
      AppsMenuItem(
        label: "سۆزلۈك باشقۇرۇش",
        imageAsset: "assets/pictures/agenda.png",
        animationTag: "Word-Management-Tag",
          action: (context) => Navigator.of(context).push(MaterialPageRoute(builder: (context) => WordManagementPage()))
      ),
      AppsMenuItem(
          label: "ئەگەشكەنلىرىم",
          imageAsset: "assets/pictures/classroom.png",
        animationTag: "Me-To-Follow-Tag",
    action: (context) => Navigator.of(context).push(MaterialPageRoute(builder: (context) => MeFollowToPage()))
      ),
      AppsMenuItem(
          label: "ئەگەشكۈچىلىرىم",
          imageAsset: "assets/pictures/team.png",
        animationTag: "Follow-To-Me-Tag",
    action: (context) => Navigator.of(context).push(MaterialPageRoute(builder: (context) => ToFollowMePage()))
      ),
      AppsMenuItem(
          label: "ھەققىدە",
          imageAsset: "assets/pictures/information.png",
        animationTag: "About-Page-Logo",
          action: (context) => Navigator.of(context).push(MaterialPageRoute(builder: (context) => AboutPage()))
      ),
    ];

    return CustomScrollView(
      slivers: <Widget>[
        SliverAppBar(
          title: Text("قوشۇمچە ئىقتىدارلار", style: TextStyle(fontFamily: "ukij-title", color: Colors.white),),
          centerTitle: true,
        ),
        SliverToBoxAdapter(
          child: SizedBox(height: 20.0,),
        ),
        SliverGrid(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3,
            mainAxisSpacing: 10.0
          ),
          delegate: SliverChildListDelegate(menus.map((item) => buildItem(context, item)).toList()),
        )
      ],
    );
  }

  Widget buildItem(BuildContext context, AppsMenuItem item){
    return GestureDetector(
      onTap: (){
        item.action(context);
      },
        child: Column(
          children: <Widget>[
            Hero(tag: item.animationTag, child: Image.asset(item.imageAsset, width: 50.0, height: 50.0,),),
            Text(item.label)
          ],
        )
    );
  }
}

typedef MenuAction = void Function(BuildContext context);

class AppsMenuItem {
  String label;
  String imageAsset;
  MenuAction action;
  String animationTag;

  AppsMenuItem({this.label, this.imageAsset, this.action, this.animationTag});
}